/**
  ******************************************************************************
  * @file    APP_SPEED.h
  * @author  Feirui_Joe
  * @version V0.1
  * @date    07/26/2010
  * @brief   Outputs Driver
  ******************************************************************************
  * @copy
  *
  * <h2><center>&copy; COPYRIGHT 2010 Feirui</center></h2>
  */ 



/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef  __APP_SPEED_H__
#define  __APP_SPEED_H__


#ifdef __cplusplus
 extern "C" {
#endif


/**
  * @brief  INCLUDE FILES.
  */


/**
  * @brief GLOBALS RAM definition
  */
#ifdef   APP_SPEED_GLOBALS
#define  APP_SPEED_EXT
#else
#define  APP_SPEED_EXT  extern
#endif

/* Speed Signal Freq */                      
#define SignalTimerCountOffset               37
#define SignalCycleFilterLimit               ((uint32_t)(TIM3CountCLK_FREQ/100000))         /*100KHZ */
#define SignalBufferReadyTimLimit            ((uint32_t)(TIM3CountCLK_FREQ/20    ))        /* 20HZ */
#define SignalBufferReadyCntLimit            1000
#define SignalBufferLossSpeedBit             DEF_BIT_15
#define VALMSOverTime_PICK_IN                60                                            /* 2HZ */


/* Collect Freq Signal */
APP_SPEED_EXT uint16_t PICKIN_PulseCnt;
APP_SPEED_EXT uint8_t  PICKIN_TimerCNT;
APP_SPEED_EXT uint8_t  PICKIN_OVTimCNT;

/* Data Result */
APP_SPEED_EXT uint8_t  SpeedDataReadyFlag;
APP_SPEED_EXT uint16_t SpeedDataReadyPulse;
APP_SPEED_EXT uint32_t SpeedDataReadyTicnt;

APP_SPEED_EXT uint16_t SpeedTempReadyPulse;
APP_SPEED_EXT uint32_t SpeedTempReadyTicnt;

/* Speed Result */
APP_SPEED_EXT uint32_t SpeedRotationValue;


/* Speed Alarm */
APP_SPEED_EXT uint8_t SpeedAlarmSta_OverShut  ;       /* 0:Inactive 1:Active */
APP_SPEED_EXT uint8_t SpeedAlarmSta_OverWarn  ;       /* 0:Inactive 1:Active */
APP_SPEED_EXT uint8_t SpeedAlarmSta_HighShut  ;       /* 0:Inactive 1:Active */
APP_SPEED_EXT uint8_t SpeedAlarmSta_HighWarn  ;       /* 0:Inactive 1:Active */
APP_SPEED_EXT uint8_t SpeedAlarmSta_LowWarn   ;       /* 0:Inactive 1:Active */
APP_SPEED_EXT uint8_t SpeedAlarmSta_LowShut   ;       /* 0:Inactive 1:Active */
APP_SPEED_EXT uint8_t SpeedAlarmSta_LossSignal;       /* 0:Inactive 1:Active */
APP_SPEED_EXT uint8_t SpeedAlarmSta_GenRunning;       /* 0:Inactive 1:Active */
APP_SPEED_EXT uint8_t SpeedAlarmSta_CrankOK   ;       /* 0:Inactive 1:Active */
APP_SPEED_EXT uint8_t SpeedAlarmSta_FastLoad  ;       /* 0:Inactive 1:Active */

APP_SPEED_EXT uint16_t SpeedAlarmTiCnt_OverShut  ;
APP_SPEED_EXT uint16_t SpeedAlarmTiCnt_OverWarn  ;
APP_SPEED_EXT uint16_t SpeedAlarmTiCnt_HighShut  ;
APP_SPEED_EXT uint16_t SpeedAlarmTiCnt_HighWarn  ;
APP_SPEED_EXT uint16_t SpeedAlarmTiCnt_LowWarn   ;
APP_SPEED_EXT uint16_t SpeedAlarmTiCnt_LowShut   ;
APP_SPEED_EXT uint16_t SpeedAlarmTiCnt_LossSignal;
APP_SPEED_EXT uint16_t SpeedAlarmTiCnt_GenRunning;
APP_SPEED_EXT uint16_t SpeedAlarmTiCnt_CrankOK   ;
APP_SPEED_EXT uint16_t SpeedAlarmTiCnt_FastLoad  ;



#define SpeedInputTimingFreq                    10      /* 10HZ */
#define SpeedLossSignalRPMLimit                 100     /* 10.0RPM */
#define SpeedGenRunningRPMLimit                  9      /*  0.9RPM */
#define SpeedGenRunningTimLimit                  9      /* 0.9s  */
#define SpeedCrankTimLimit                       2      /* 0.2s  */

#define SpeedFastLoadTimLimit                   20      /* 2.0s  */


/*********************************************/
/*********************************************/


APP_SPEED_EXT uint8_t SpeedInputsLayerHandle(OS_FLAGS os_value);
APP_SPEED_EXT void PORInputsStaReset_SPEED(void);
APP_SPEED_EXT void PORLocalRAMReset_SPEED(void);
APP_SPEED_EXT void PORGlobalRAMReset_SPEED(void);
APP_SPEED_EXT void TIM3_IRQHandler(void);
APP_SPEED_EXT void InitalSpeedInputsAlarmOperation(uint8_t InitOrd);



#ifdef __cplusplus
}
#endif


#endif   /*  __APP_SPEED_H__  */

/******************* (C) COPYRIGHT 2010 Feirui *****END OF FILE****/
